package com.ruoyi.web.controller.base;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.base.domain.BaseBasin;
import com.ruoyi.base.service.IBaseBasinService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 流域Controller
 * 
 * @author ruoyi
 * @date 2025-07-27
 */
@RestController
@RequestMapping("/base/basin")
public class BaseBasinController extends BaseController
{
    @Autowired
    private IBaseBasinService baseBasinService;

    /**
     * 查询流域列表
     */
//    @PreAuthorize("@ss.hasPermi('base:basin:list')")
    @GetMapping("/list")
    public TableDataInfo list(BaseBasin baseBasin)
    {
        startPage();
        List<BaseBasin> list = baseBasinService.selectBaseBasinList(baseBasin);
        return getDataTable(list);
    }

    //    @PreAuthorize("@ss.hasPermi('base:basin:listall')")
    @GetMapping("/listall")
    public AjaxResult listall(BaseBasin baseBasin)
    {
        List<BaseBasin> list = baseBasinService.selectBaseBasinList(baseBasin);
        return AjaxResult.success(list);
    }

    /**
     * 导出流域列表
     */
//    @PreAuthorize("@ss.hasPermi('base:basin:export')")
//    @Log(title = "流域", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseBasin baseBasin)
    {
        List<BaseBasin> list = baseBasinService.selectBaseBasinList(baseBasin);
        ExcelUtil<BaseBasin> util = new ExcelUtil<BaseBasin>(BaseBasin.class);
        util.exportExcel(response, list, "流域数据");
    }

    /**
     * 获取流域详细信息
     */
//    @PreAuthorize("@ss.hasPermi('base:basin:query')")
    @GetMapping(value = "/getinfo/{ID}")
    public AjaxResult getInfo(@PathVariable("ID") String ID)
    {
        return success(baseBasinService.selectBaseBasinByID(ID));
    }

    /**
     * 新增流域
     */
//    @PreAuthorize("@ss.hasPermi('base:basin:add')")
//    @Log(title = "流域", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody BaseBasin baseBasin)
    {
        return toAjax(baseBasinService.insertBaseBasin(baseBasin));
    }

    /**
     * 修改流域
     */
//    @PreAuthorize("@ss.hasPermi('base:basin:edit')")
//    @Log(title = "流域", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody BaseBasin baseBasin)
    {
        return toAjax(baseBasinService.updateBaseBasin(baseBasin));
    }

    /**
     * 删除流域
     */
//    @PreAuthorize("@ss.hasPermi('base:basin:remove')")
//    @Log(title = "流域", businessType = BusinessType.DELETE)
	@GetMapping("/remove/{IDs}")
    public AjaxResult remove(@PathVariable String[] IDs)
    {
        return toAjax(baseBasinService.deleteBaseBasinByIDs(IDs));
    }
}
